/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mekegi.whoanthro;

import android.content.ContentValues;
import com.mekegi.whoanthro.Sql.ChildAdapter;
import java.util.Date;
import java.util.HashMap;

/**
 *
 * @author Arsen Abdusalamov <duburlan@gmail.com>
 */
public class Measure extends AbstractModel {

    protected Integer mHeight;
    protected Integer mGirthHead;
    protected Integer mWeight;
    protected Date mCreatedAt;
    protected Child mChild;
    public final static String TABLE_NAME = "measure";
    public static final String KEY_HEIGHT = "Height";
    public static final String KEY_WEIGHT = "Weight";
    public static final String KEY_GIRTH_HEAD = "GirthHead";
    public static final String KEY_CREATED_AT = "CreatedAt";
    public static final String KEY_FK_CHILD = "fk_child";
    protected static final HashMap<String, Integer> COLUMNS_MAP;

    static {
        HashMap<String, Integer> aMap = new HashMap<String, Integer>();
        aMap.put(KEY_ID, FIELD_TYPE_INTEGER);
        aMap.put(KEY_HEIGHT, FIELD_TYPE_INTEGER);
        aMap.put(KEY_WEIGHT, FIELD_TYPE_INTEGER);
        aMap.put(KEY_GIRTH_HEAD, FIELD_TYPE_INTEGER);
        aMap.put(KEY_CREATED_AT, FIELD_TYPE_INTEGER);
        aMap.put(KEY_FK_CHILD, FIELD_TYPE_INTEGER);
        COLUMNS_MAP = aMap;
    }

//<editor-fold defaultstate="collapsed" desc="constructors">
    public Measure() {
    }

    public Measure(Child mChild, Long id) {
        super(id);
        this.mChild = mChild;
    }

    public Measure(Long id) {
        super(id);
    }

    public Measure(Integer mHeight, Integer mGirthHead, Integer mWeight, Date mCreatedAt) {
        this.setHeight(mHeight);
        this.setGirthHead(mGirthHead);
        this.setWeight(mWeight);
        this.setCreatedAt(mCreatedAt);
    }

    public Measure(Long id, Integer mHeight, Integer mGirthHead, Integer mWeight, Date mCreatedAt) {
        super(id);
        this.setHeight(mHeight);
        this.setGirthHead(mGirthHead);
        this.setWeight(mWeight);
        this.setCreatedAt(mCreatedAt);
    }
//</editor-fold>

//{{{<editor-fold defaultstate="collapsed" desc="getter setter">
    public HashMap<String, Integer> getColumnsMap() {
        return COLUMNS_MAP;
    }

    public final Integer getHeight() {
        return mHeight;
    }

    public final void setHeight(Integer mHeight) {
        this.mHeight = mHeight;
    }

    public final Child getChild() {
        return mChild;
    }

    public final void setChild(Long childId) {
        ChildAdapter childAdapter = new ChildAdapter(null);
        this.mChild = (Child)childAdapter.findItemByPK(childId);
    }

    public final void setChild(Child child) {
        this.mChild = child;
    }

    public final Integer getGirthHead() {
        return mGirthHead;
    }

    public final void setGirthHead(Integer mGirthHead) {
        this.mGirthHead = mGirthHead;
    }

    public final Integer getWeight() {
        return mWeight;
    }

    public final void setWeight(Integer mWeight) {
        this.mWeight = mWeight;
    }

    public final Date getCreatedAt() {
        return mCreatedAt;
    }

    public final void setCreatedAt(Date mCreatedAt) {
        this.mCreatedAt = mCreatedAt;
    }

    public final void setCreatedAt(Long mills) {
        this.mCreatedAt = new Date(mills);;
    }
//</editor-fold>

    @Override
    public void fromContentValues(ContentValues contentValues) {
        super.fromContentValues(contentValues);

        if (contentValues.containsKey(KEY_HEIGHT)) {
            this.setHeight(contentValues.getAsInteger(KEY_HEIGHT));
        }
        if (contentValues.containsKey(KEY_WEIGHT)) {
            this.setWeight(contentValues.getAsInteger(KEY_WEIGHT));
        }
        if (contentValues.containsKey(KEY_GIRTH_HEAD)) {
            this.setGirthHead(contentValues.getAsInteger(KEY_GIRTH_HEAD));
        }
        if (contentValues.containsKey(KEY_CREATED_AT)) {
            this.setCreatedAt(contentValues.getAsLong(KEY_CREATED_AT));
        }
    }

    @Override
    public ContentValues toContentValues() {
        ContentValues result = super.toContentValues();

        result.put(KEY_HEIGHT, this.getHeight());
        result.put(KEY_WEIGHT, this.getWeight());
        result.put(KEY_GIRTH_HEAD, this.getGirthHead());
        result.put(KEY_CREATED_AT, this.getCreatedAt().getTime());

        return result;
    }

    @Override
    public String getTextForView() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
